//
//  ProtocolViewController.m
//  Light
//
//  Created by 骁唐 on 15/11/27.
//  Copyright © 2015年 骁唐. All rights reserved.
//

#import "ProtocolViewController.h"
#import "LandingViewController.h"

@interface ProtocolViewController ()<UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate>
//协议webView。加载本地的文件
@property (weak, nonatomic) IBOutlet UIWebView *protocolWebView;
//背景图片
@property (weak, nonatomic) IBOutlet UIImageView *backGround;
@property (weak,nonatomic) IBOutlet UITableView * tableView;//表格

@end

@implementation ProtocolViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    //SXW__标记，设置背景
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    TJJLog(@"viewDidLoad标记");
    [self configTableViewString];//配置参数 TableView
//    [self configWebView]; //使用webView,显示效果不好
}

#pragma mark -
#pragma mark 使用webView展示，背景不透明（暂时放弃使用）
- (void)configWebView
{
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"protocol1.txt" ofType:nil];
//    //    NSURL *url = [NSURL fileURLWithPath:path];
//    NSData * data = [NSData dataWithContentsOfFile:path];
//
//    [self.protocolWebView setBackgroundColor:[UIColor clearColor]];//设置背景图片
//    self.protocolWebView.backgroundColor = [UIColor clearColor];
//
//    [self.protocolWebView loadData:data MIMEType:@"text/plain" textEncodingName:@"UTF-8" baseURL:nil];
//    //    self.protocolWebView.hidden = YES;
//
//    if ([TJJDefines isNull:data])
//    {
//        NSString * stringProtocol = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//        NSDictionary * attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};
//    //        CGRect rect = [textToMeasure boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
//    //                                                  options:NSStringDrawingUsesLineFragmentOrigin
//    //                                               attributes:attributes
//    //                                                  context:nil];
//        UILabel * labelText = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 30)];
//        labelText.font = [UIFont systemFontOfSize:14];
//        labelText.text = stringProtocol;
//        labelText.textColor = [UIColor whiteColor];
//        labelText.backgroundColor = [UIColor clearColor];
//    //        CGSize sizeString = [labelText.text sizeWithAttributes:@{NSFontAttributeName: labelText.font}];
//        CGSize sizeString=[labelText.text sizeWithFont:[UIFont systemFontOfSize:10] constrainedToSize:CGSizeMake(SCREEN_WIDTH, 100000) lineBreakMode:UILineBreakModeWordWrap
//                     ]; //200为UILabel的宽度，1000是预设的一个高度，表示在这个范围内
//        UIScrollView * scrollViewBg = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
//        [scrollViewBg setContentSize:CGSizeMake(0, sizeString.height+40)];
//        [scrollViewBg setContentMode:UIViewContentModeTopLeft];
//
//        [scrollViewBg setBackgroundColor:[UIColor clearColor]];
//
//        [self.view addSubview:scrollViewBg];
//
//
//        labelText.numberOfLines = 0;
//        labelText.frame = CGRectMake(0, 20, SCREEN_HEIGHT, sizeString.height+20);
//        [scrollViewBg addSubview:labelText];
//
//        TJJLog(@"%d行",(int)sizeString.height);
//    //        如何从新 iOS 7 方法 sizeWithAttributes 返回 CGSize 的多行文本？
//    //
//    //        我想这要产生相同的结果为 sizeWithFont:constrainedToSize。
//
//    //        NSString *text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu urna quis lacus imperdiet scelerisque a nec neque. Mauris eget feugiat augue, vitae porttitor mi. Curabitur vitae sollicitudin augue. Donec id sapien eros. Proin consequat tellus in vehicula sagittis. Morbi sed felis a nibh hendrerit hendrerit. Lorem ipsum dolor sit.";
//
//    //        CGSize textSize = [text sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:16.0] }];
//        
//    //        此方法只生成单个文本行的高度
//    }
}
#pragma mark -
#pragma mark 使用tableView展示，背景透明）
- (void)configTableViewString
{
    self.protocolWebView.hidden = YES;//隐藏webViwe
    NSString *path = [[NSBundle mainBundle] pathForResource:@"protocol1.txt" ofType:nil];
    NSData * data = [NSData dataWithContentsOfFile:path];
    NSString * htmlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    UILabel * labelContent = [[UILabel alloc] initWithFrame:CGRectZero];
    labelContent.font = [UIFont systemFontOfSize:14];
    CGSize size = [htmlString sizeWithFont:labelContent.font constrainedToSize:CGSizeMake(SCREEN_WIDTH - 40, MAXFLOAT) lineBreakMode:NSLineBreakByCharWrapping];//计算文字尺寸
    labelContent.text = htmlString;//设置内容展示
    labelContent.numberOfLines = 0;
    labelContent.frame = CGRectMake(20, 20, size.width, size.height);//设置frame
    labelContent.textColor = [UIColor whiteColor];//设置字体颜色
    UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, size.height+100)];
    [headView addSubview:labelContent];
    [headView setBackgroundColor:[UIColor clearColor]];
    [self.tableView setTableHeaderView:headView];
    [self.tableView setBackgroundColor:[UIColor clearColor]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark 导航返回方式点击
- (IBAction)backClick {
//    NSLog(@"用户协议，关于我们----%u",[self.view subviews].count);
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
